<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const {
          testHelpers: { createDirectLineEmulator }
        } = window;

        const { directLine, store } = createDirectLineEmulator();

        WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));

        await pageConditions.uiConnected();

        await directLine.emulateIncomingActivity({
          attachments: [
            {
              contentType: 'image/png',
              contentUrl:
                'data:text/plain;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAK0lEQVQ4T2P8z8Dwn4GKgHHUQIpDczQMKQ5ChtEwHA1DMkJgNNmQEWhoWgBMAiftPRtHngAAAABJRU5ErkJggg=='
            }
          ],
          type: 'message'
        });

        const imageElement = pageElements.activities()[0].querySelector('img');

        const imageURL = imageElement.getAttribute('src');

        // THEN: This test is only relevant it is a blob URL.
        expect(imageURL.startsWith('blob:')).toEqual(true);

        const res = await fetch(imageURL);

        const contentType = res.headers.get('content-type');

        // THEN: Content type should be rectified to "application/octet-stream".
        expect(contentType).toBe('application/octet-stream');

        // THEN: Should show the image properly.
        await host.snapshot('local');
      });
    </script>
  </body>
</html>
